/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef UPDATE_LITE_DEFINES_H
#define UPDATE_LITE_DEFINES_H

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

#define DEVICE_ID_MAX_LEN 64

#define UPDATE_LITE_SAMGR_SERVICE "updatelservice"
#define UPDATE_LITE_SAMGR_FEATURE "updatelfeature"
#define SECURITY_MAGIC 0xABCD1234

// #define MSG_STARTOTA "startota"
// #define MSG_GETCURRENTINFO "getcurrentinfo"



// typedef struct UpdateLiteIdentify {
//     uint32_t length;
//     uint8_t identity[DEVICE_ID_MAX_LEN];
// } UpdateLiteIdentify;

typedef struct RequestOption {
    uint64_t challenge;
    uint32_t timeout;
    uint32_t extra;
} RequestOption;

typedef struct UpdateLiteInfo {
    uint32_t transType;    //transType
    uint32_t msgtype;
    uint32_t msgid;
    const uint8_t *payload;
    uint32_t payloadlen;
} UpdateLiteInfo;



typedef void UpdateLiteCallback(struct UpdateLiteInfo *info);
typedef void downloadCallback(struct UpdateLiteInfo *info, int success);

uint32_t GetFirmwareInfo(struct UpdateLiteInfo *info, char * url, downloadCallback callback);
// uint32_t GetFirmwareInfo(struct UpdateLiteInfo *info, char * url, downloadCallback callback);

//uint32_t DownloadFirmware(struct UpdateLiteInfo *info);
uint32_t DownloadFirmware(struct UpdateLiteInfo *info, char* url, downloadCallback callback);

uint32_t ReportUpdateResultInfo(struct UpdateLiteInfo *info);



//typedef void UpdateLiteCallback(const UpdateLiteIdentify *identify, struct UpdateLiteInfo *info);

#define DEFAULT_OPTION NULL

enum {
    UPDATELITE_MQTT = 1,
    UPDATELITE_BLT = 2
};

enum {
    MSG_STARTOTA = 1,     //start ota
    MSG_GETCURRENTINFO = 2,   //get current info
    MSG_FIRMWAREINFO = 3,    //Firmware info
    MSG_DOWNLOADINFO = 9,    //download info
};

// API enum
//UpdateLiteXxxApi
// enum {
//     CMD_SET_DEVICE_SECURITY_LEVEL = 1,
//     CMD_UPDATE_LITE_XXX_API = 99,
// };

// //
// enum {
//     SUCCESS = 0,
//     ERR_INVALID_PARA = 1,
//     ERR_INVALID_LEN_PARA = 2,
//     ERR_NO_MEMORY = 3,
//     ERR_MEMORY_ERR = 4,
//     ERR_NO_CHALLENGE = 5,
//     ERR_NO_CRED = 6,
//     ERR_SA_BUSY = 7,
//     ERR_TIMEOUT = 8,
//     ERR_NOEXIST_REQUEST = 9,
//     ERR_INVALID_VERSION = 10,
//     ERR_OEM_ERR = 11,
//     ERR_HUKS_ERR = 12,
//     ERR_CHALLENGE_ERR = 13,
//     ERR_NOT_ONLINE = 14,
//     ERR_INIT_SELF_ERR = 15,
//     ERR_JSON_ERR = 16,
//     ERR_IPC_ERR = 17,
//     ERR_IPC_REGISTER_ERR = 18,
//     ERR_IPC_REMOTE_OBJ_ERR = 19,
//     ERR_IPC_PROXY_ERR = 20,
//     ERR_IPC_RET_PARCEL_ERR = 21,
//     ERR_PROXY_REMOTE_ERR = 22,
//     ERR_MSG_NEIGHBOR_FULL = 23,
//     ERR_MSG_FULL = 24,
//     ERR_MSG_ADD_NEIGHBOR = 25,
//     ERR_MSG_NOT_INIT = 26,
//     ERR_MSG_CREATE_WORKQUEUE = 27,
//     ERR_NEED_COMPATIBLE = 28,
//     ERR_REG_CALLBACK = 29,
//     ERR_PERMISSION_DENIAL = 30,
//     ERR_REQUEST_CODE_ERR = 31,
//     ERR_VERIFY_MODE_CRED_ERR = 32,
//     ERR_VERIFY_SIGNED_MODE_CRED_ERR = 33,
//     ERR_VERIFY_MODE_HUKS_ERR = 34,
//     ERR_PROFILE_CONNECT_ERR = 35,
//     ERR_MSG_OPEN_SESSION = 36,
//     ERR_QUERY_WAITING = 37,
//     ERR_NOEXIST_DEVICE = 38,
//     ERR_NOEXIST_COMMON_PK_INFO = 39,
//     ERR_ECC_VERIFY_ERR = 40,
//     ERR_GET_CLOUD_CRED_INFO = 41,
//     ERR_CALL_EXTERNAL_FUNC = 42,
//     ERR_PARSE_NONCE = 43,
//     ERR_ROOT_PUBKEY_NOT_RIGHT = 44,
//     ERR_PARSE_CLOUD_CRED_DATA = 45,
//     ERR_PARSE_PUBKEY_CHAIN = 46,
//     ERR_CHECK_CRED_INFO = 47,
//     ERR_ATTEST_NOT_READY = 48,
//     ERR_CLOUD_CRED_NOT_EXIST = 49,
//     ERR_DEFAULT = 0xFFFF
// };

#ifdef __cplusplus
}
#endif

#endif // UPDATE_LITE_DEFINES_H
